package com.ruoyi.web.controller.blogs;

import com.ruoyi.blogs.domain.BsDirection;
import com.ruoyi.blogs.domain.BsGroup;
import com.ruoyi.blogs.service.IBsGroupService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 分类Controller
 * 
 * @author ruoyi
 * @date 2022-11-04
 */
@RestController
@RequestMapping("/blogs/group")
public class BsGroupController extends BaseController
{
    @Autowired
    private IBsGroupService bsGroupService;

    /**
     * 查询分类列表
     */
    @PreAuthorize("@ss.hasPermi('blogs:group:list')")
    @GetMapping("/list")
    public TableDataInfo list(BsGroup bsGroup)
    {
        startPage();
        List<BsGroup> list = bsGroupService.selectBsGroupList(bsGroup);
        return getDataTable(list);
    }

    /**
     * 查询全部分类列表
     */
    @PreAuthorize("@ss.hasPermi('blogs:group:list')")
    @GetMapping("/allList")
    public AjaxResult allList(BsGroup bsGroup)
    {
        bsGroup.setVisible(0);
        List<BsGroup> list = bsGroupService.selectBsGroupList(bsGroup);
        return AjaxResult.success(list);
    }

    /**
     * 导出分类列表
     */
    @PreAuthorize("@ss.hasPermi('blogs:group:export')")
    @Log(title = "分类", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BsGroup bsGroup)
    {
        List<BsGroup> list = bsGroupService.selectBsGroupList(bsGroup);
        ExcelUtil<BsGroup> util = new ExcelUtil<BsGroup>(BsGroup.class);
        util.exportExcel(response, list, "分类数据");
    }

    /**
     * 获取分类详细信息
     */
    @PreAuthorize("@ss.hasPermi('blogs:group:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(bsGroupService.selectBsGroupById(id));
    }

    /**
     * 新增分类
     */
    @PreAuthorize("@ss.hasPermi('blogs:group:add')")
    @Log(title = "分类", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BsGroup bsGroup)
    {
        return toAjax(bsGroupService.insertBsGroup(bsGroup));
    }

    /**
     * 修改分类
     */
    @PreAuthorize("@ss.hasPermi('blogs:group:edit')")
    @Log(title = "分类", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BsGroup bsGroup)
    {
        return toAjax(bsGroupService.updateBsGroup(bsGroup));
    }

    /**
     * 删除分类
     */
    @PreAuthorize("@ss.hasPermi('blogs:group:remove')")
    @Log(title = "分类", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(bsGroupService.deleteBsGroupByIds(ids));
    }
}
